import request from "./request";
import {scope, client_id, client_secret, grant_type} from '@/const/const'

// 发送验证码
export function getPhone(data) {
    return request({
      url: `/auth/phone/sms/verification/${data.phone}`,
      method: "get"
    });
}

// 获取系统基本信息
// ico、title、登录背景、logo
export function getDomain(params) {
    return request({
      url: "/auth/api/domain",
      method: "get",
      headers: {
        isToken: false
      },
      isNotCancel:true,
      params: { client_id }
    });
  }
  
export const loginByUsername = (username, password, code, randomStr) => {
  return request({
    url: `/auth/oauth2/token`,
    headers: {
      isToken: false,
    },
    method: "post",
    params: { username, password, grant_type, scope, client_id, client_secret }
  });
};

export const refreshToken = (refresh_token, tenantId) => {
    const grant_type = "refresh_token";
    return request({
      url: "/auth/oauth2/token",
      headers: {
        isToken: false,
      },
      method: "post",
      params: { grant_type, scope, client_id, client_secret, refresh_token: refresh_token, switch: tenantId }
    });
};

// 验证码登录
export function codeLogin(data) {
    return request({
      url: "/auth/oauth2/token",
      method: "post",
      headers: {
        isToken: false,
      },
      params: { client_id, client_secret, login_other_auth_parameter: data, grant_type: 'jvs' }
    });
}

// 退出登录
export const loginoutHandle = () => {
  return request({
    url: `/auth/token/logout`,
    method: "get"
  });
};

// 获取可登录的方式
export function getCanLogin() {
  return request({
    url: `/auth/just`,
    method: "get",
    headers:{
      isToken : false
    },
    params: { client_id }
  });
}

// 公众号登录二维码
export const getOffLoginQcode = (uuid) => {
  return request({
    url: `/auth/wx/qr/code/login/${uuid}`,
    method: "get",
    params: { client_id }
  });
}

// 定时检查二维码状态
export const checkQrcodeState = (uuid) =>{
  return request({
    url: `/auth/wx/qr/code/check/${uuid}`,
    method: "get"
  });
}

// 注册发送验证码
export function getRegPhoneCode(data) {
  return request({
    url: `/auth/phone/sms/register/${data.phone}`,
    method: "get"
  });
}

// 获取钉钉扫码相关信息
export function getInfoByLoginType(params) {
  return request({
    url: `/auth/just/config`,
    method: "get",
    headers: {
      isToken: false,
    },
    params: Object.assign(params,{ client_id:client_id })
  });
}
